package com.example.demo.service.impl;

import com.example.demo.entity.Team;
import com.example.demo.repository.TeamRepository;
import com.example.demo.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TeamServiceImpl implements TeamService {

    @Autowired
    private TeamRepository teamRepository;

    // 获取所有球队
    public List<Team> getAllTeams() {
        return teamRepository.findAll();
    }

    // 根据ID获取球队
    public Optional<Team> getTeamById(Long id) {
        return teamRepository.findById(id);
    }

    // 新增或更新球队
    public Team saveTeam(Team team) {
        return teamRepository.save(team);
    }

    // 删除球队
    public void deleteTeamById(Long id) {
        teamRepository.deleteById(id);
    }
}